package com.cheer.websocket;


import com.cheer.service.AuthService;
import com.cheer.util.SpringContextUtil;

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

/**
 * @author cheer
 */
public class GetHttpSessionConfigurator extends ServerEndpointConfig.Configurator {

    private AuthService authService = SpringContextUtil.getBean(AuthService.class);

    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        HttpSession session = (HttpSession) request.getHttpSession();
        sec.getUserProperties().put("userId", authService.getUserId(session));
    }
}
